package com.example.demo.manmanage.service.impl;

import com.example.demo.manmanage.mapper.ManMapper;
import com.example.demo.manmanage.service.ManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(propagation = Propagation.REQUIRED)
public class ManServiceImpl implements ManService {
    @Autowired
    private ManMapper manMapper;

    /**
     * @Description 根据条件查询所有驾驶人员信息
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> queryAllMen(Map<String, Object> param) {
        List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
        resultList = manMapper.queryAllMenMapper(param);
        Map<String,String> countMap = manMapper.queryAllMenCountMapper(param);
        Object totalSize = countMap.get("total");
        Map<String,Object> resultMap = new HashMap<String, Object>();
        resultMap.put("data",resultList);
        resultMap.put("totalnum",totalSize);
        return resultMap;

    }

    /**
     * @Description 查询所有车辆下拉
     * @Author zhangxue
     * @Date 16:21 2018/9/17
     * @Param
     * @retrun
     **/
    @Override
    public List<Map<String, Object>> queryAllSjName(Map<String,Object> param) {
        List<Map<String,Object>> resultList = new ArrayList<Map<String, Object>>();
        resultList = manMapper.queryAllSjName(param);
        return resultList;
    }

    /**
     * @Description 根据条件查询所有空闲驾驶人员信息
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> queryAllFreeMen(Map<String, Object> param) {
        List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
        resultList = manMapper.queryAllFreeMenMapper(param);
        Map<String,String> countMap = manMapper.queryAllFreeMenCountMapper(param);
        Object totalSize = countMap.get("total");
        Map<String,Object> resultMap = new HashMap<String, Object>();
        resultMap.put("data",resultList);
        resultMap.put("totalnum",totalSize);
        return resultMap;

    }

    /**
         * @Description 新增驾驶人员信息
         * @Author zhangxue
         * @Date 11:18 2018/7/12
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveMan(Map<String, Object> param) {
        int i = manMapper.saveManMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
     * @Description 删除驾驶人员信息
     * @Author zhangxue
     * @Date 14:31 2018/7/13
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> delMan(Map<String, Object> param) {
        int i = manMapper.delManMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
         * @Description 修改驾驶人员信息信息
         * @Author zhangxue
         * @Date 17:48 2018/7/13
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> editMan(Map<String, Object> param) {
        int i = manMapper.editManMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
         * @Description 添加授权书资料路径
         * @Author zhangxue
         * @Date 11:38 2018/7/13
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveUploadBook(Map<String, Object> param) {
        int i = manMapper.saveUploadBookMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
         * @Description 添加执照路径
         * @Author zhangxue
         * @Date 16:39 2018/7/16
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveUploadLicense(Map<String, Object> param) {
        int i = manMapper.saveUploadLicenseMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
     * @Description 添加身份证照片
     * @Author zhangxue
     * @Date 16:39 2018/7/16
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> saveUploadCard(Map<String, Object> param) {
        int i = manMapper.saveUploadCardMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
     * @Description 查看车辆详情
     * @Author zhangxue
     * @Date 16:17 2018/7/13
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> initManInfo(Map<String, Object> param) {
        Map<String,Object> tempMap = manMapper.queryManInfoByID(param);
        return tempMap;
    }

    /**
     * @Description 新增展位信息
     * @Author zhangxue
     * @Date 15:10 2018/7/13
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> saveZWInfo(Map<String, Object> param) {
        int i = manMapper.saveZWInfoMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
         * @Description 删除展位信息
         * @Author zhangxue
         * @Date 17:00 2018/7/13
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> delZWInfo(Map<String, Object> param) {
        int i = manMapper.delZWInfoMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            resultMap.put("status","0");
        }
        return resultMap;
    }

}
